package a66weding.com.jiehuntong.activity.me;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.GlobalApplication;

/**
 * 这是支付配送方式的界面
 * Created by Administrator on 2016/7/29.
 */
public class MePayDistributionActivity extends MeBaseActivity implements View.OnClickListener {
    private LinearLayout mBackLay;
    private TextView mBackContentTv;
    private TextView mHeaderTitleTv;
    private TextView mRightTitleTv;
    private TextView mPay1Tv;
    private TextView mPay2Tv;
    private TextView mPay3Tv;
    private RelativeLayout mPay1Raly;
    private RelativeLayout mPay2Raly;
    private RelativeLayout mPay3Raly;
    private ImageView mPay1Iv;
    private ImageView mPay2Iv;
    private ImageView mPay3Iv;
    private Button mPayBtn;
    private RadioGroup mPay1Rg;
    private RadioGroup mPay2Rg;
    private RadioButton mPay1Rb;
//    private RadioButton mPay2Rb;
    private RadioButton mPay3Rb;
    private RadioButton mPay4Rb;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me_pay_distrbution);
        ((GlobalApplication) getApplication()).getActivityManager().addActivity("MePayDistributionActivity", this);

        initview();
    }

    private void initview() {
        mBackLay = (LinearLayout) findViewById(R.id.lay_head_backlay);
        mPay1Raly = (RelativeLayout) findViewById(R.id.rl_me_pay_distrbution_1);
        mPay2Raly = (RelativeLayout) findViewById(R.id.rl_me_pay_distrbution_2);
        mPay3Raly = (RelativeLayout) findViewById(R.id.rl_me_pay_distrbution_3);
        mBackContentTv = (TextView) findViewById(R.id.headleft_title_tv);
        mHeaderTitleTv = (TextView) findViewById(R.id.headcenter_title_tv);
        mRightTitleTv = (TextView) findViewById(R.id.headright_title_tv);
        mPay1Tv = (TextView) findViewById(R.id.iv_me_pay_distrbution_1);
        mPay2Tv = (TextView) findViewById(R.id.iv_me_pay_distrbution_2);
        mPay3Tv = (TextView) findViewById(R.id.iv_me_pay_distrbution_3);
        mPay1Iv = (ImageView) findViewById(R.id.img_me_pay_distrbution_1);
        mPay2Iv = (ImageView) findViewById(R.id.img_me_pay_distrbution_2);
        mPay3Iv = (ImageView) findViewById(R.id.img_me_pay_distrbution_3);
        mPayBtn = (Button) findViewById(R.id.btn_me_pay_distrbution);
        mPay1Rg = (RadioGroup) findViewById(R.id.rg_me_pay_distrbution_1);
        mPay2Rg = (RadioGroup) findViewById(R.id.rg_me_pay_distrbution_2);
        mPay1Rb = (RadioButton) findViewById(R.id.rb_me_pay_1);
        mPay3Rb = (RadioButton) findViewById(R.id.rb_me_pay_3);
        mPay4Rb = (RadioButton) findViewById(R.id.rb_me_pay_4);

        mBackContentTv.setText("订单");
        mHeaderTitleTv.setText("支付配送方式");
        mRightTitleTv.setVisibility(View.GONE);

        mBackLay.setOnClickListener(this);
        mPay1Raly.setOnClickListener(this);
        mPay2Raly.setOnClickListener(this);
        mPay3Raly.setOnClickListener(this);
        mPayBtn.setOnClickListener(this);

        mPay1Rb.setChecked(true);
        mPay3Rb.setChecked(true);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.lay_head_backlay: //点击我的，返回到上一级界面
                finish();

                break;
            case R.id.rl_me_pay_distrbution_1: //点击我的，返回到上一级界面
                mPay1Tv.setTextColor(getResources().getColor(R.color.colorMainRed));
                mPay2Tv.setTextColor(getResources().getColor(R.color.colorFontGray2));
                mPay3Tv.setTextColor(getResources().getColor(R.color.colorFontGray2));
                mPay1Iv.setVisibility(View.VISIBLE);
                mPay2Iv.setVisibility(View.INVISIBLE);
                mPay3Iv.setVisibility(View.INVISIBLE);
                break;
            case R.id.rl_me_pay_distrbution_2: //点击我的，返回到上一级界面
                mPay1Tv.setTextColor(getResources().getColor(R.color.colorFontGray2));
                mPay2Tv.setTextColor(getResources().getColor(R.color.colorMainRed));
                mPay3Tv.setTextColor(getResources().getColor(R.color.colorFontGray2));
                mPay1Iv.setVisibility(View.INVISIBLE);
                mPay2Iv.setVisibility(View.VISIBLE);
                mPay3Iv.setVisibility(View.INVISIBLE);

                break;
            case R.id.rl_me_pay_distrbution_3: //点击我的，返回到上一级界面
                mPay1Tv.setTextColor(getResources().getColor(R.color.colorFontGray2));
                mPay2Tv.setTextColor(getResources().getColor(R.color.colorFontGray2));
                mPay3Tv.setTextColor(getResources().getColor(R.color.colorMainRed));
                mPay1Iv.setVisibility(View.INVISIBLE);
                mPay2Iv.setVisibility(View.INVISIBLE);
                mPay3Iv.setVisibility(View.VISIBLE);
                break;
            case R.id.btn_me_pay_distrbution: //点击我的，返回到上一级界面
                int number1 = mPay1Iv.getVisibility();
                int number2 = mPay2Iv.getVisibility();
                int number3 = mPay3Iv.getVisibility();
                String pay;
                String distrbution;
                String goTime;
                if (number1 == 0) {         // 1选中
                    goTime = (String) mPay1Tv.getText();
                } else if (number2 == 0) {  // 2选中
                    goTime = (String) mPay2Tv.getText();
                } else {                    // 3选中
                    goTime = (String) mPay3Tv.getText();
                }
                if (mPay1Rb.isChecked()){
                    pay = "在线支付";
                } else {
                    pay = "线下汇款";
                }
                if (mPay3Rb.isChecked()) {
                    distrbution = "快递配送";
                } else {
                    distrbution = "上门取货";
                }
                // 用EventBus把数据传过去
                MyPayEvent event = new MyPayEvent(pay,distrbution,goTime);
                EventBus.getDefault().post(event);
                finish();
                break;
        }
    }



    public class MyPayEvent{
        public String pay;
        public String distrbution;
        public String goTime;

        public MyPayEvent(String pay ,String distrbution,String goTime) {
            this.pay = pay;
            this.distrbution = distrbution;
            this.goTime = goTime;
        }
    }


}
